import React from 'react';
import {
    Form,
    Input,
    Button,
    Table,
    Icon,
    Radio,
    InputNumber,
    Checkbox,
    Modal,
    message,
    notification,
    Affix,
    Upload,
    Select
} from 'antd';

import InnerTable from 'components/DBTable/InnerTable.js';
import MessageView from 'components/Bill/messageView.js';
import ajax from '../../../utils/ajax';
const FormItem = Form.Item;
const ButtonGroup = Button.Group;
const Option = Select.Option;

var _this;

/**
 * 内部表格组件
 */
class LoanInner extends InnerTable {


    /**
     * 构造器，好像是用来初始化的？
     * @param props
     */
    constructor(props) {
        super(props);

        this.columns = [
            {
                dataIndex: 'Id',
                title: '',
                fixed: "left"
            },
            {
                dataIndex: 'code',
                title: '机构代码',
                dataType: 'varchar',               
            },
            {
                dataIndex: 'contract',
                title: '合同号',
                dataType: 'varchar',
            },
            {
                dataIndex: 'loanEnd',
                title: '放款结果',
                dataType: 'varchar',
            },
            {
                dataIndex: 'fail',
                title: '失败原因',
                dataType: 'varchar',
            },
            {
                dataIndex: 'bankTime',
                title: '银行回盘时间',
                dataType: 'varchar',
            },
            {
                dataIndex: 'approval',
                title: '审批结果',
                dataType: 'varchar',
            },
            {
                dataIndex: 'approvalFail',
                title: '审批拒绝原因',
                dataType: 'varchar',
            },
            {
                dataIndex: 'start',
                title: '创建时间',
                dataType: 'varchar',
            },
            {
                dataIndex: 'file',
                title: '来源文件名',
                dataType: 'varchar',
            },
            {
                dataIndex: 'allNum',
                title: '更新总数',
                dataType: 'varchar',
            }];
        this.state = {
            desVisible: false,
            dn: '',
            des: '',
            newDes: '',
            examineVisible: false,
            status: -1
        };
    }


    /**
     * 这里好像是用来配置那些按钮之类的
     * @returns {Array}
     */
    prepareToolBar = function () {


    }
    onDes = (text, record) => {
        var _this = this;
        let dn = record.dealNum;
        _this.setState({ dn: dn });
        _this.setState({ des: record.des });
        this.setState({ desVisible: true });
        // ajax.post({
        //       url: "/accountbill/getDes",
        //       params: {dn:dn},
        //       success: function (res) {
        //         _this.setState({des : ''});
        //         _this.setState({ des : res.data });
        //         _this.setState({ desVisible: true });
        //       }
        // })
    }

    desOk = () => {
        var _this = this;
        let dn = _this.state.dn;
        let newDes = _this.state.des;
        const hide = message.loading('');
        ajax.post({
            url: "/accountbill/modifyDes",
            params: { dn: dn, newDes: newDes },
            success: function (res) {
                hide();
                if (res.errorCode == 200) {
                    notification.success({
                        message: '修改成功',
                    });
                    _this.props.refresh();
                    _this.setState({ desVisible: false });
                } else {
                    notification.error({
                        message: res.moreInfo,
                    });
                }
            }
        })

    }

    desCancel = () => {
        this.setState({ desVisible: false });
    }

    getInputValue = (e) => {
        var _this = this;
        _this.setState({ des: e.target.value });
    }

    onExamine = (text, record) => {
        var _this = this;
        let dn = record.dealNum;
        _this.setState({ dn: dn });
        _this.setState({ examineVisible: true });

    }

    examineOk = () => {
        var _this = this;
        let dn = _this.state.dn;
        let status = _this.state.status;
        const hide = message.loading('');
        ajax.post({
            url: "/accountbill/modifyStatus",
            params: { dn: dn, status: status },
            success: function (res) {
                hide();
                if (res.errorCode == 200) {
                    notification.success({
                        message: '审核成功',
                    });
                    _this.props.refresh();
                    _this.setState({ examineVisible: false });
                } else {
                    notification.error({
                        message: res.moreInfo,
                    });
                }
            }
        })
    }

    examineCancel = () => {
        this.setState({ examineVisible: false });
    }

    getSelectValue = (value) => {
        var _this = this;
        _this.setState({ status: value });
    }


    /**
     * 请求之前，先处理数据
     * @param obj
     * @returns {*}
     */
    handleData = (data) => {

    }
    getDataSource = () => {
        if (this.props.data) {
            return this.props.data;
        }
    }
    render() {
        const columns = this.columns;
        return (
            <div className="userList">
                <Table columns={columns} dataSource={this.getDataSource()} pagination={false} />
                <Modal title="修改备注" visible={this.state.desVisible} onOk={this.desOk}
                    onCancel={this.desCancel}>
                    <textarea className="noteTextArea" maxLength="120" onChange={this.getInputValue} placeholder='请输入备注' style={{ height: 80, width: 490 }} value={this.state.des} />
                </Modal>

                <Modal title="审核" visible={this.state.examineVisible} onOk={this.examineOk}
                    onCancel={this.examineCancel}>
                    <div>请选择</div>
                    <Select
                        style={{ width: 200 }}
                        placeholder="请选择"
                        onChange={this.getSelectValue}
                    >
                        <Option value="0">不通过</Option>
                        <Option value="1">通过</Option>
                    </Select>
                </Modal>
            </div>
        )
    }


}

export default LoanInner;
